﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.NewsInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int NewsId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(NewsId);
				}
			}
		}
			
	private void ShowInfo(int NewsId)
	{
		Maticsoft.BLL.NewsInfo bll=new Maticsoft.BLL.NewsInfo();
		Maticsoft.Model.NewsInfo model=bll.GetModel(NewsId);
		this.lblNewsId.Text=model.NewsId.ToString();
		this.txtNewsTitle.Text=model.NewsTitle;
        this.CKEditorControl1.Text = model.NewsContent;
		this.txtNewsAuthor.Text=model.NewsAuthor;
		this.txtNewsCreateTime.Text=model.NewsCreateTime.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtNewsTitle.Text.Trim().Length==0)
			{
				strErr+="NewsTitle不能为空！\\n";	
			}
            if (this.CKEditorControl1.Text.Trim().Length == 0)
			{
				strErr+="NewsContent不能为空！\\n";	
			}
			if(this.txtNewsAuthor.Text.Trim().Length==0)
			{
				strErr+="NewsAuthor不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtNewsCreateTime.Text))
			{
				strErr+="NewsCreateTime格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int NewsId=int.Parse(this.lblNewsId.Text);
			string NewsTitle=this.txtNewsTitle.Text;
            string NewsContent = this.CKEditorControl1.Text;
			string NewsAuthor=this.txtNewsAuthor.Text;
			DateTime NewsCreateTime=DateTime.Parse(this.txtNewsCreateTime.Text);


			Maticsoft.Model.NewsInfo model=new Maticsoft.Model.NewsInfo();
			model.NewsId=NewsId;
			model.NewsTitle=NewsTitle;
			model.NewsContent=NewsContent;
			model.NewsAuthor=NewsAuthor;
			model.NewsCreateTime=NewsCreateTime;

			Maticsoft.BLL.NewsInfo bll=new Maticsoft.BLL.NewsInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
